#include "service_arch/service_arch.h"
#include "service_arch/service_base_impl.h"
#include "database/simple_db_pool.h"
#include "base/logging.h"

#include "GenericCounter_types.h"
#include "GenericCounter_constants.h"
#include "GenericCounter.h"

#include <thrift/concurrency/Mutex.h>
#include <thrift/concurrency/TimerManager.h>

#include "redis_executor/redis_executor.h"

namespace jztzp {

class ReloadCountTask;

class GenericCounterHandler : public GenericCounterIf, public ServiceBaseImpl {
  friend class ReloadCountTask;
 public:
  GenericCounterHandler();

  virtual ~GenericCounterHandler();

  virtual int32_t Get(const int32_t business_type, const int64_t business_id);
  virtual bool Add(const int32_t business_type, const int64_t business_id, const int32_t delta);
  bool ReloadRedis();
  bool UpdateDatabase(int business_type, int64_t business_id, int delta);
 private:
  base::SimpleConnectionPool db_pool_; 
  RedisExecutor redis_exec_;
  concurrency::TimerManager timer_manager_;
  shared_ptr<concurrency::ThreadManager> thread_manager_; // = concurrency::ThreadManager::newSimpleThreadManager(10, 20);
  // concurrency::ThreadManager thread_manager_;
};

}
